package com.sun.springboot_mq_ack1.sender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author shkstart
 * @create 2021-10-25 21:42
 */
@Slf4j
@RestController
public class Producer1 {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public static final String CONFIRM_ROUTING_KEY = "confirm_key";
    public static final String CONFIRM_EXCHANGE_NAME = "confirm_exchange";
    @GetMapping("sendMsg/{message}")
    public void send(@PathVariable String message){

        //第一种情况
        CorrelationData correlationData2=new CorrelationData("2");
        String routingKey2="confirm_key1";
        this.rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME,routingKey2,message,correlationData2);
        log.info(" 发送消息 id 为:{} 内容为:{}",correlationData2.getId(),message);
        //第一种情况
        CorrelationData correlationData1=new CorrelationData("1");
        this.rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME,CONFIRM_ROUTING_KEY,message,correlationData1);
        log.info(" 发送消息 id 为:{} 内容为:{}",correlationData1.getId(),message);
    }

}
